

import React, { Component } from 'react';
import Son from "./Son"

export default class index extends Component {
    constructor(props){
        super(props);
        this.child=null;
        
    }

    testFn=(sonRef)=>{
      this.child = sonRef;
      // sonRef.parent = this;
      this.child.parent = this;
    }

    chuanToSon=()=>{
      this.child.chuan("嘿嘿");
    }

    fnParent=(str)=>{
      console.log("子给父传的数据",str);
    }

  render() {    
    return (
      <div>
        <h1>父组件---子组件（使用ref）</h1>
        <input type="button" value="传给子" onClick={this.chuanToSon} />
        <hr/>
        <Son onRef={this.testFn} ></Son>

      </div>
    )
  }
}
